﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>编辑模板</title>
<link rel=stylesheet href="/codemirror/lib/codemirror.css" />
<link rel=stylesheet href="/codemirror/theme/default.css" />
<link rel=stylesheet href="/codemirror/css/docs.css" />
<style type="text/css">
body,form{
	margin:0;
	padding:0;
}
#codeMain{
	width:100%;
	height:100%;
	position:absolute;
}
#codeMenu{
	width:100%;
	/*height:8%;*/
	height:34px;
	overflow:hidden;
	position:relative;
	background:#eee;
	border:1px solid gray;
	z-index:100;
}
#codeMenu ul{margin:4px;}
#codeMenu ul li{list-style:none;margin:4px;float:left}
#codeMenu ul li a{cursor:pointer}
#code{
	width:100%;
}

.CodeMirror {
	width: 100%;
	height:100%;
	position:absolute;
	left:0;
	bottom:0;
	border: 1px solid gray;
	border-top:0;
}

.CodeMirror-scroll {
	width: 100%;
	/*height:92%;*/
	height:88%;
	top:38px;
	top*:34px;
	overflow: auto;
	position:absolute;
	left:0;
}
.activeline {background: #f0fcff !important;}
</style>
<script language="javascript" src="/include/manage/js/jquery.js"></script>
<script src="/codemirror/lib/codemirror.js"></script>
<script src="/codemirror/mode/xml/xml.js"></script>
<script src="/codemirror/mode/javascript/javascript.js"></script>
<script src="/codemirror/mode/css/css.js"></script>
<script src="/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="/codemirror/mode/velocity/velocity.js"></script>
</head>
<body>
<div id="codeMain">
	<div id="codeMenu">
		<ul>
			<li><a href="javascript:saveTemplate()"><img src="/codemirror/images/save.gif" border="0" align="absmiddle" />保存</a></li>
			<li><a href="javascript:unDo()"><img src="/codemirror/images/undo.gif" border="0" align="absmiddle" />撤销</a></li>
			<li><a href="javascript:reDo()"><img src="/codemirror/images/redo.gif" border="0" align="absmiddle" />重做</a></li>
			<li><a href="javascript:switchMode()"><img src="/codemirror/images/go_to_line.gif" border="0" align="absmiddle" />模式切换</a></li>
		</ul>
	</div>
	<form>
	<textarea id="code" name="code">#if($content)$!content#else//KnifeCMS模板#end</textarea>
	</form>
</div>
<script language="javascript" type="text/javascript">
jQuery.ajaxSetup ({  
	cache: false
});

function unDo(){
	editor.undo();
}

function reDo(){
	editor.redo();
}

var nowMode="text/html";
function switchMode(){
	if(nowMode=="text/html"){
		nowMode="text/velocity";
	}else{
		nowMode="text/html";
	}
	editor.setOption("mode", nowMode);
}

var delay;
// Initialize CodeMirror editor with a nice html5 canvas demo.
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
	lineNumbers: true,
	matchBrackets: true,
	mode: nowMode,
	tabSize: 2,
	indentWithTabs: true,
	lineWrapping: true,
	onCursorActivity: function() {
		editor.setLineClass(hlLine, null);
		hlLine = editor.setLineClass(editor.getCursor().line, "activeline");
	}
});

var hlLine = editor.setLineClass(0, "activeline");

function saveTemplate(){
	var postdata=editor.getValue();
	if(postdata.length>0){
		$.post("/manage_template_ajax.ad",{parameter:'save',sid:'$!sid',name:'$!name',content:postdata},function(data){
			if(data.length>0){
				alert(data);
			}
		});
	}
}
</script>
</body>
</html>